﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using BOHVote.DAL;
using BOHVote.Common;

namespace BOHVote.BLL
{
   public static class InterviewClass
   {
       #region << Delete  >>
       public static int DelQuestionByID(string strQID)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.DeleteQuestions(strQID);
       }
       #endregion


       public static int DisableCanUseBySubject(string subjectID, string ApplyPeriod)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateCanUseBySubject(subjectID, ApplyPeriod, "1");
       }

       #region <<  select  >>

       public static string getQuestionCanUsebyQID(string QID)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.getQuestionCanUsebyQID(QID);
       }

       public static DataSet getSTotleNumber(string strSubjectID, string strApplyPeriodID)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.dstGetTotalNumber(strSubjectID,strApplyPeriodID,"S");

       }

       public static DataSet getGTotleNumber(string strSubjectID, string strApplyPeriodID)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.dstGetTotalNumber(strSubjectID, strApplyPeriodID, "G");
       }

       public static DataSet getResults(string strApplyName, string strUnitID, string strSubjectID, string strSpecialityID, string strPass, string strType, string strApplyPeriodID,string strEvaluationType)
       {
           InterviewProvider ip = new InterviewProvider();
           DataSet dst = ip.dstGetAllResults(strApplyName, strUnitID, strSubjectID, strSpecialityID, strPass, strType, strApplyPeriodID,strEvaluationType);
           DataColumn dc = new DataColumn("JobRank");
           dst.Tables[0].Columns.Add(dc);
           foreach (DataRow dr in dst.Tables[0].Rows)
           {
               dr["JobRank"] = OtherClass.getJobRankName(dr["JobRankID"].ToString());
           }

           return dst;
       }
       public static DataSet getAllResults(string strApplyName, string strUnitID, string strSubjectID, string strSpecialityID, string strPass, string strType, string strApplyPeriodID)
       {
           //InterviewProvider ip = new InterviewProvider();
           DataSet dst = InterviewClass.getResults(strApplyName, strUnitID, strSubjectID, strSpecialityID, strPass, strType, strApplyPeriodID,"G");
           foreach (DataRow dr in dst.Tables[0].Rows)
           { 
               if(!string.IsNullOrEmpty(dr["PassInd"].ToString()))
               {
                   if (dr["PassInd"].ToString() == "Y")
                       dr["PassInd"] = "通过";
                   if (dr["PassInd"].ToString() == "N")
                       dr["PassInd"] = "未通过";  
               }

               dr["UnitID"] = UnitClass.getUnitName(dr["UnitID"].ToString());
               dr["GovernID"] = UnitClass.GetGovernName(dr["GovernID"].ToString());
               dr["SpecialityID"] = Subject.getSpecialityName(dr["SpecialityID"].ToString());
               dr["SubjectID"] = Subject.getSubjectNameBySubjectID(dr["SubjectID"].ToString());
           }

           return dst;
       }

       public static DataSet getQuestionByID(string strQID)
       {
           InterviewProvider ip = new InterviewProvider();

           return ip.dstQuestionByID(strQID);
       }

       public static DataSet getAllAQuestions()
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.getAllQuestions(string.Empty, "", "", "A","-1");
       }

       public static DataSet getQuestions(string Content, string strSubject, string strSpecialty,string Status,string applyPeriod)
       {
           InterviewProvider ip = new InterviewProvider();
           DataSet dst = ip.getAllQuestions(Content, strSubject, strSpecialty, Status, applyPeriod);
           DataColumn dc = new DataColumn("JobRank");
           dst.Tables[0].Columns.Add(dc);
           DataColumn dc1 = new DataColumn("No");
           dst.Tables[0].Columns.Add(dc1);

           int i = 0;
           foreach (DataRow dr in dst.Tables[0].Rows)
           {
               dr["No"] = ++i;
               //if(dr["Question_JobRank"].ToString()!="0")
               //    dr["JobRank"] = "共通";
               //else
               if (dr["Question_JobRank"].ToString() == "0")
                   dr["JobRank"] = "全部正高";
               else if (dr["Question_JobRank"].ToString() == "1")
                   dr["JobRank"] = "全部副高";
               else if (dr["Question_JobRank"].ToString() == "-1")
                   dr["JobRank"] = "全部职称";
               else
                   dr["JobRank"] = OtherClass.getJobRankName(dr["Question_JobRank"].ToString());
               dr["Question_Subject"] = Subject.getSubjectNameBySubjectID(dr["Question_Subject"].ToString());
               dr["Question_Content"] = common.RemoveHTML(dr["Question_Content"].ToString().Trim());
               if (!string.IsNullOrEmpty(dr["ApplyPeriodID"].ToString()))
               {
                   dr["ApplyPeriodID"] = dr["ApplyPeriodID"] + " 年度";
               }
               if (dr["Question_Specialty"].ToString() == "0")
                   dr["Question_Specialty"] = "全部专业[共性题]";
               else
                   dr["Question_Specialty"] = Subject.getTestSpecialityName(dr["Question_Specialty"].ToString());//Subject.getSpecialityName(dr["Question_Specialty"].ToString());
           }

           return dst;
       }

       public static DataSet getQuestions(string Content, string strSubject, string strSpecialty, string JobRank, string isCommon, string Status, string jobLevel,string ApplyperiodID)
       {
           InterviewProvider ip = new InterviewProvider();
           DataSet dst = ip.getAllQuestions(Content, strSubject, strSpecialty, JobRank, isCommon, Status, jobLevel, ApplyperiodID);
           DataColumn dc = new DataColumn("JobRank");
           dst.Tables[0].Columns.Add(dc);
           DataColumn dc1 = new DataColumn("No");
           dst.Tables[0].Columns.Add(dc1);

           int i = 0;
           foreach (DataRow dr in dst.Tables[0].Rows)
           {
               dr["No"] = ++i;
               //if(dr["Question_JobRank"].ToString()!="0")
               //    dr["JobRank"] = "共通";
               //else
               if (dr["Question_JobRank"].ToString() == "0")
                   dr["JobRank"] = "正高共通";
               else if (dr["Question_JobRank"].ToString() == "1")
                   dr["JobRank"] = "副高共通";
               else
                    dr["JobRank"] = OtherClass.getJobRankName(dr["Question_JobRank"].ToString());
               dr["Question_Subject"] = Subject.getSubjectNameBySubjectID(dr["Question_Subject"].ToString());
               if (dr["Question_Specialty"].ToString() == "0")
                   dr["Question_Specialty"] = "共通";
               else
                   dr["Question_Specialty"] = Subject.getTestSpecialityName(dr["Question_Specialty"].ToString());//Subject.getSpecialityName(dr["Question_Specialty"].ToString());
           }

           return dst;
       }
       #endregion

       #region <<  Insert  >>

       public static int SaveQustionCheck(string QID, string UserID, string SubjectID,string ApplyID)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.InsertQuestionCheck(QID, UserID, SubjectID, ApplyID);
       }

       public static int SaveInterview(string QTitle, string QContent, string QAnswer, int intJobRank, string QSubject, string QSpecialty, string subSpecialty, string ApplyPeriod)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.InsertQuestions(QTitle, QContent, QAnswer, intJobRank, QSubject, QSpecialty, "A", subSpecialty, ApplyPeriod);
       }

       public static int UpdateInterview(string QID, string QTitle, string QContent, string QAnswer, int intJobRank, string QSubject, string QSpecialty,string subSpecialty)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateQuestions(QID, QTitle, QContent, QAnswer, intJobRank, QSubject, QSpecialty, "A",subSpecialty);
       }

       public static int UpdateInterviewStatus(string QID, string Status)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateStatus(QID, Status);
       }
       #endregion

       public static int UpdateCanUse(string QID, string Mod)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateCanUseByQID(QID, Mod);
       }

       public static int UpdateAllStatusQuestions(string status)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateStatusQuestions(status);
       }

       public static string CheckResultApplyID(string ApplyID, string EvaluationType)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.CheckResultApplyID(ApplyID, EvaluationType);

       }

       public static int InsertInterviewResult(string ApplyID,string ResultSum, string EvaluationType,string TotalNumber, string AgreeNumber, string DenyNumber, string AbstrainNumber, string comment, string ActualNumber)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.InsertInsterviewResult(ApplyID, EvaluationType, ResultSum,TotalNumber, AgreeNumber, DenyNumber, AbstrainNumber, comment, ActualNumber);
       }

       public static int UpdateInterviewResult(string ResultID,string ResultSum, string TotalNumber, string AgreeNumber, string DenyNumber, string AbstrainNumber, string comment, string ActualNumber)
       {
           InterviewProvider ip = new InterviewProvider();
           return ip.UpdateInterviewResult(ResultID, ResultSum,TotalNumber, AgreeNumber, DenyNumber, AbstrainNumber, comment, ActualNumber);
       }
   }
}
